package callgraph.domain;

public class ProfilingFilter {

    private final WildcardMatcher includes;
    private final WildcardMatcher excludes;

    public ProfilingFilter(JarConfig jarConfig) {
        this.includes = new WildcardMatcher(toVMName(jarConfig.getIncludes()));
        this.excludes = new WildcardMatcher(toVMName(jarConfig.getExcludes()));
    }

    public ProfilingFilter(String includes, String excludes) {
        this.includes = new WildcardMatcher(toVMName(includes));
        this.excludes = new WildcardMatcher(toVMName(excludes));
    }

    private String toVMName(final String srcName) {
        return srcName.replace('.', '/');
    }

    public boolean needInject(String name) {
        return includes.matches(name) && !excludes.matches(name);
    }
}
